﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DIS_Client.Helpers
{
    public class XMLHelper
    {
        public static XmlDocument XMLReader(string filename)
        {
            XmlDocument xmlR = new XmlDocument();
            try
            {
                xmlR.Load(filename);
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }

            return xmlR;
        }

        public static void GetAnnouncement(string filename)
        {
            GlobalVariables.g_colInfoSpecific = new List<InfoSpecific>();
            XmlDocument xmlDoc = XMLReader(filename);
            if (xmlDoc != null)
            {
                XmlElement xmlEle = xmlDoc.DocumentElement;
                var xmlLst = xmlEle.SelectNodes("Element");
                foreach (XmlNode xmlItem in xmlLst)
                {
                    var info = new InfoSpecific
                    {
                        Name = xmlItem.Attributes.GetNamedItem("Name").InnerText,
                        Area = xmlItem.Attributes.GetNamedItem("Area").InnerText,
                        Report = xmlItem.SelectSingleNode("Report").InnerText
                    };
                    GlobalVariables.g_colInfoSpecific.Add(info);
                }
            }
        }
    }
}
